package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import dao.UserInfoDAO;
import dao.UserInfoDaoJdbcImpl;
import modle.userInfo;
import modle.users;


/**
 * Servlet implementation class Person
 */
@WebServlet("/PersonalCenterServlet")
public class PersonalCenterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PersonalCenterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("::::::::::::::PersonalCenterServlet:::::::::::");
		//获取信息
		JSONObject jsonObject = new JSONObject();
		//获取个人信息
		//学生
		users user = (users) request.getSession().getAttribute("user");
		System.out.println(user.toString());
//		String userID = request.getParameter("userID");
		String userID = user.getUsername();
		UserInfoDAO uid = new UserInfoDaoJdbcImpl();
		userInfo userInfo = null;
		userInfo = uid.readUserInfo(userID);
		jsonObject.put("userInfo",userInfo);
		
		System.out.println("::::::::::::::end::PersonalCenterServlet:::::::::::");
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
	
		String jsonStr = JSON.toJSONString(jsonObject);
		System.out.println("111111111111111111111");
		System.out.println(jsonStr);
		PrintWriter out = response.getWriter();
		out.println(jsonStr);
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
